package com.flyoil.petromp.adapter.adapter_matter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.flyoil.petromp.R;
import com.flyoil.petromp.base.BaseRecyAdapter;
import com.flyoil.petromp.entity.entity_matter.MatterEntity;
import com.flyoil.petromp.utils.OrderUtl.OrderListUtil;

/**
 * Created by songzhiiyn on 2017/10/11.
 * 待办事项、已办事项、首页列表的适配器
 */

public class ItemMatterAdapter extends BaseRecyAdapter<ItemMatterAdapter.ViewHolder, MatterEntity> {
    public ItemMatterAdapter(Context mContext) {
        super(mContext);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(mInflater.inflate(R.layout.item_matter_list_adapter, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ViewHolder viewHolder = (ViewHolder) holder;
        final MatterEntity entity = getItemData(position);
        if (entity.getAppliedUsername()!= null) {
            viewHolder.tv_name.setText(entity.getFlowName() + "_" + entity.getAppliedUsername());
        } else {
            viewHolder.tv_name.setText(entity.getFlowName());
        }
        viewHolder.tv_number.setText(entity.getSn());
        viewHolder.tv_type.setText("[" + entity.getBillType() + "]");
        viewHolder.tv_time.setText("创建时间：" + entity.getBillCreateTime());
        viewHolder.img_icon.setImageResource(OrderListUtil.getImageResource(entity.getBillType()));
        viewHolder.line_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onItemClickListener != null) {
                    onItemClickListener.Onclick(position, entity);
                }
            }
        });
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        private TextView tv_name;
        private TextView tv_number;
        private TextView tv_type;
        private TextView tv_time;
        private ImageView img_icon;
        private LinearLayout line_layout;


        public ViewHolder(View itemView) {
            super(itemView);
            tv_name = itemView.findViewById(R.id.tv_item_matter_list_name);
            tv_number = itemView.findViewById(R.id.tv_item_matter_list_number);
            tv_type = itemView.findViewById(R.id.tv_item_matter_list_type);
            tv_time = itemView.findViewById(R.id.tv_item_matter_list_time);
            img_icon = itemView.findViewById(R.id.img_matter_list_icon);
            line_layout = itemView.findViewById(R.id.line_item_matter_list_layout);
        }
    }
}
